'use strict';
avalon.define({
    $id: "vm-form",
    is_disabled: false,
    form_data: {
        name: '',
        is_effect: 1,
        role_access: []
    },
    check: function check() {
        var self = this;
        if ($checkAction.checkEmpty(self.form_data.name)) {
            layer.msg('请输入权限名称');
            return false;
        } else {
            return true;
        }
    },

    submit: function submit() {
        // 提交更新
        var self = this;
        if (self.check()) {
            var loading = layer.load();
            $handleAjax.handle({
                url: APP_ROOT + "/mapi/index.php?ctl=user_two&act=role_insert",
                isTip: false,
                data: self.form_data
            }).done(function (result) {
                layer.close(loading);
                if (result.status == 1) {
                    layer.msg(result.error || '操作成功', {
                        time: 1000
                    });
                    setTimeout(function () {
                        location.href = TMPL_REAL + "/index.php?ctl=user_two&act=role_index";
                    }, 1000);
                } else {
                    layer.msg(result.error || '操作失败');
                }
            }).fail(function (err) {
                console.log(err);
            });
        }
    }
});